package com.zhangyue.core.config;

import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
import com.zhangyue.core.route.AutoBindRoutes;
import com.zhangyue.web.model._MappingKit;

public class BaseConfig extends JFinalConfig{
private Routes routes;

public void configConstant(Constants me) {
loadPropertyFile("system.properties");
PropKit.use("system.properties");

me.setEncoding("UTF-8");
me.setI18nDefaultBaseName("i18n");
me.setMaxPostSize(1024 * 1024 * 5);
me.setI18nDefaultLocale(getProperty("locale"));
me.setError401View("/stu_login.jsp");
me.setError403View("/stu_login.jsp");
me.setError404View("/404.html");
me.setError500View("/500.html");
me.setDevMode(getPropertyToBoolean("DevMode"));
}

public void configRoute(Routes me) {
this.routes = me;
routes.add(new AutoBindRoutes());
}

public void configEngine(Engine engine) {
engine.addSharedFunction("common/pagination.html");
}

public void configPlugin(Plugins plugins) {
DruidPlugin dp = new DruidPlugin(PropKit.get("jdbc.url"), PropKit.get("jdbc.username"), PropKit.get("jdbc.password").trim());
plugins.add(dp);
ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(dp);
_MappingKit.mapping(activeRecordPlugin);
plugins.add(activeRecordPlugin);
}

public void configInterceptor(Interceptors interceptors) {

}

public void configHandler(Handlers handlers) {

}

public static void main(String[] args) {
JFinal.start("src/main/webapp", 80, "/wxbase");
}
}